home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7809 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: system() & error detection
  5. Date: Thu, 29 Feb 96 00:05:00 GMT
  6. Organization: none
  7. Message-ID: <825552300snz@genesis.demon.co.uk>
  8. References: <4gt24g$dba@ncar.ucar.edu> <4gt7f4INNt1j@keats.ugrad.cs.ubc.ca>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4gt7f4INNt1j@keats.ugrad.cs.ubc.ca>
  15.            c2a192@ugrad.cs.ubc.ca "Kazimir Kylheku" writes:
  16.  
  17. >In article <4gt24g$dba@ncar.ucar.edu>,
  18. >James Adams <jadams@sage.cgd.ucar.edu> wrote:
  19. > >Hello,
  20. > >
  21. > >        I am attempting to use the system() call in order to have a
  22. > >user-specified command execute in my program.
  23. > >
  24. > >        I am wondering how I can check whether or not the command has
  25. > >completed successfully ?  I don't want the program to continue if the
  26. > >call I make from system() produces some sort of error.  I'd like to be
  27. > >able to do something like the following:
  28. > >
  29. > >        result = system(command);
  30. > >        if (result == ERROR)
  31. > >          exit(0);
  32. > >
  33. > >Is there anyway to do this ?  Should I be using something other than
  34. > >system() ?
  35. >
  36. >Try one of the member of the ``exec'' family of functions. These are defined by
  37. >the POSIX.1 standard, not ISO/ANSI C.
  38.  
  39. Eh? exec*() replaces the currently executing program with the new one. Once
  40. the new program is successfully started the old one can never be resumed.
  41.  
  42. >Exec lets you get the return value.
  43.  
  44. All you can ever get is a failure code if the new program couldn't be
  45. executed. you were probably thinking of a combination of fork(), exec*()
  46. and wait*(). Pure comp.unix.programmer fodder however.
  47.  
  48. >It is also more secure, since system() can
  49. >be exploited in ways which violate system security.
  50.  
  51. However system() is an ANSI function and it does return a result code which
  52. will probably serve in this case. It is implementation defined as far as
  53. C is concerned. According to Lewine "The POSIX.2 standard provides several
  54. hundred pages of documentation on the arguments to system()." :-)
  55.  
  56. -- 
  57. -----------------------------------------
  58. Lawrence Kirby | fred@genesis.demon.co.uk
  59. Wilts, England | 70734.126@compuserve.com
  60. -----------------------------------------
  61.